﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SmartCity.ProcessEngine.Api.Read.Application.Command.FormCategory;
using SmartCity.ProcessEngine.Api.Read.Application.Command.FormField;
using SmartCity.ProcessEngine.Api.Read.Application.Command.From;
using SmartCity.ProcessEngine.Api.Read.Application.Command.Industry;
using SmartCity.ProcessEngine.Api.Read.Dtos;
using SmartCity.ProcessEngine.Domain.Entities;
using SmartCity.ProcessEngine.ErrorCode;
using SmartCity.ProcessEngine.Infrastructure.Extention;
using System.Collections.Generic;

namespace SmartCity.ProcessEngine.Api.Read.Controllers
{
    /// <summary>
    /// 流程引擎控制器
    /// </summary>

    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ProcessEngineController : ControllerBase
    {
        private readonly IMediator mediator;

        public ProcessEngineController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 查询行业列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>

        [HttpGet]
        public Task<ApiResult<List<IndustryDto>>> GetIndustry([FromQuery] GetIndustryCommand request)
        {

            return mediator.Send(request);
        }

        /// <summary>
        /// 查询流程表单类别列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<FormCategoryDto>>> SearchFormCategory([FromQuery] SearchFormCategoryCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 获取表单类别的编号
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>

        [HttpGet]
        public Task<ApiResult<string>> GetFormCategoryCode([FromQuery] GetFormCategoryCodeCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 分页查询流程表单列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiPaging<FormDto>> GetFormPages([FromQuery] GetFormCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 获取类型枚举里的属性列表
        /// 1.我们定义好了枚举:FieldTypeEnum
        /// 2.写获取枚举列表的方法
        /// 3.返回枚举属性的字典
        /// 4.把枚举属性列表字典放到响应包装类对象中
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<KeyValuePair<int, string>>>> GetFieldTypes()
        {
            var list = EnumExtention.GetEnumValues<FieldTypeEnum>().ToList();//3.返回枚举属性的字典

            return new ApiResult<List<KeyValuePair<int, string>>>().Success("获取字段类型列表成功!", list);
        }

        /// <summary>
        /// 获取所有组件列表接口
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<KeyValuePair<int, string>>>> GetComponents() {

            var list = EnumExtention.GetEnumValues<ComponentEnum>().ToList(); //返回枚举组件所有属性列表
            ApiResult<List<KeyValuePair<int, string>>> res = new ApiResult<List<KeyValuePair<int, string>>>();

            res.Msg = "获取组件列表成功";

            return new ApiResult<List<KeyValuePair<int, string>>>().Success("获取组件列表成功",list);
        }

        /// <summary>
        /// 查询指定表单id的表单明细字段列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public   Task<ApiResult<List<FormFieldDto>>> GetFormFields([FromQuery]GetFormFieldCommand request) {
            return mediator.Send(request);
        }
    }

}
